<?php
session_start();

$message="Subarna, Sujan";
$front_include_path = "views/frontend/";
$action_path = "actions";
if (isset($_POST['username'])) {
    $username = $_POST['username'];
}

if (isset($_POST['password'])) {
    $password = $_POST['password'];
}
if (isset($_POST['email'])) {
    $email = $_POST['email'];
}

if ($username != "" && $password != "") {
    mysql_connect("localhost","root","");
    mysql_select_db("susudo");
   $query="SELECT * FROM `users` WHERE `username`='$username' or `email`='$username' AND `password`='$password'" ;

    $result=mysql_query($query);
    
    if (mysql_num_rows($result)>0) {

        $userdata = mysql_fetch_assoc($result);
        
        $_SESSION['is_login'] = true;
        $_SESSION['user_id'] = $userdata['id'];
        $_SESSION['username'] = $userdata['username'];
        $_SESSION['email'] = $userdata['email'];
        
        header("location: ../frontend.php");
    }
    else {
       header("location: ../login.php");
    }
    mysql_close();

}else {
    header("location: ../login.php");
}

?>